import { createWithEqualityFn } from "zustand/traditional";

interface tempInfo {
  title: string;
  description: string;
  templateName: string;
  order: number;
  classify: number;
}
export type State = {
  currentTab?: string;
  index?: number;
  showLogin?: boolean;
  isLogin?: boolean;
  htmlString?: string;
  downloading?: boolean;
  isMobile?: boolean;
  isWeixin?: boolean;
  fontScale?: number;
  myResumes?: any[];
  wordList?: any[];
  tempInfo?: tempInfo;
};

export type Actions = {
  setCurrentTab: (d: string) => void;
  setIndex: (d: number) => void;
  setShowLogin: (d: boolean) => void;
  setIsLogin: (d: boolean) => void;
  setHtml: (html: string) => void;
  setDownloading: (loading: boolean) => void;
  setFontScale: (fontScale: number) => void;
  setMyResumes: (myResumes: any[]) => void;
  setTempInfo: (p: tempInfo) => void;
  setWordList: (p: any[]) => void;
};

export type Store = State & Actions;

export const defaultInitState: State = {
  currentTab: "content",
  showLogin: false,
  isLogin: false,
  downloading: false,
  htmlString: "",
  isMobile: false,
  isWeixin: false,
  index: 0,
  fontScale: 1,
  myResumes: [],
  wordList: [],
  tempInfo: {
    title: "",
    description: "",
    templateName: "tpl1",
    order: 0,
    classify: 0,
  },
};

export const createCommonStore = (initState) => {
  return createWithEqualityFn<Store>()((set, get) => ({
    ...defaultInitState,
    ...initState,
    setShowLogin: (data) => {
      set((state) => ({ showLogin: data }));
    },
    setIsLogin: (data) => {
      set((state) => ({ isLogin: data }));
    },
    setCurrentTab: (data) => {
      set((state) => ({ currentTab: data }));
    },
    setIndex: (data) => {
      set((state) => ({ index: data }));
    },
    setHtml: (html) => {
      set((state) => ({ htmlString: html }));
    },
    setDownloading: (loading) => {
      set((state) => ({ downloading: loading }));
    },
    setFontScale: (fontScale) => {
      set((state) => ({ fontScale }));
    },
    setMyResumes: (myResumes) => {
      set((state) => ({ myResumes }));
    },

    setTempInfo: (tempInfo) => {
      set((state) => ({ tempInfo }));
    },
    setWordList: (wordList) => {
      set((state) => ({ wordList }));
    },
  }));
};
